package com.cicadasmall.support.sqlbuilder.constant;

import com.cicadasmall.common.base.BaseEnum;
import com.cicadasmall.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;


/**
 * DBColumnType
 *
 * @author Jin
 */
public class DBColumnType {

    @Getter
    @AllArgsConstructor
    public enum MysqlColumnTypeEnum implements BaseEnum<String> {
        INT("int", true, false, false),
        TNY_INT("tinyint", true, false, false),
        BIG_INT("bigint", true, false, false),
        SMALL_INT("smallint", true, false, false),
        MEDIUM_INT("mediumint", true, false, false),

        /* 小数 */
        DECIMAL("decimal", false, true, false),

        /*日期*/
        DATE("date", false, true, false),
        DATE_TIME("date", false, true, false),
        TIMESTAMP("timestamp", false, true, false),

        /* 文本 */
        CHAR("char", false, false, false),
        VARCHAR("varchar", false, false, false),
        TEXT("text", false, true, true),
        MEDIUM_TEXT("mediumText", false, true, true),
        LONG_TEXT("longText", false, true, true);

        private final String value;

        private final Boolean autoIncrement;
        private final Boolean isNotLength;
        private final Boolean isNotDefaultValue;

        @Override
        public String toString() {
            return value;
        }

        public static MysqlColumnTypeEnum checkAndGet(BaseEnum columnTypeEnum) {
            return Arrays.stream(MysqlColumnTypeEnum.values()).filter(e -> e.getCode().equals(columnTypeEnum.getCode())).findFirst().orElseThrow(new ServiceException("没有找到合适的字段类型！"));
        }

        @Override
        public String getCode() {
            return value;
        }
    }

    @Getter
    @AllArgsConstructor
    public enum OracleColumnTypeEnum implements BaseEnum<String> {
        INT("NUMBER(10,0)", false, false, false),
        TNY_INT("NUMBER(10,0)", false, false, false),
        BIG_INT("NUMBER(20,0)", false, false, false),
        SMALL_INT("NUMBER(5,0)", false, false, false),
        MEDIUM_INT("NUMBER(7,0)", false, false, false),

        /* 小数 */
        DECIMAL("DECIMAL", false, false, false),

        /*日期*/
        DATE("DATE", false, false, false),
        DATE_TIME("DATE", false, false, false),
        TIMESTAMP("TIMESTAMP", false, false, false),

        /* 文本 */
        CHAR("CHAR", false, true, false),
        VARCHAR("VARCHAR2", false, true, false),
        TEXT("CLOB", false, true, false),
        MEDIUM_TEXT("CLOB", false, true, false),
        LONG_TEXT("CLOB", false, true, false);

        private final String value;

        private final Boolean autoIncrement;
        private final Boolean isCharTextFiled;
        private final Boolean isNotDefaultValue;

        @Override
        public String toString() {
            return value;
        }

        public static MysqlColumnTypeEnum checkAndGet(BaseEnum columnTypeEnum) {
            return Arrays.stream(MysqlColumnTypeEnum.values()).filter(e -> e.getCode().equals(columnTypeEnum.getCode())).findFirst().orElseThrow(new ServiceException("没有找到合适的字段类型！"));
        }

        @Override
        public String getCode() {
            return value;
        }
    }

}
